# Maintainer: Fabien Chouteau <chouteau@adacore.com>
# Based on mingw-w64-arm-none-eabi-binutils

_realname=binutils
_target=riscv64-unknown-elf

pkgbase=mingw-w64-${_target}-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_target}-${_realname}")
pkgver=2.39
pkgrel=2
pkgdesc='GNU Tools for RISC-V Embedded Processors - Binutils (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('GPL')
url='https://www.gnu.org/software/binutils/binutils.html'
groups=("${MINGW_PACKAGE_PREFIX}-${_target}-toolchain")
options=('staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://ftp.gnu.org/gnu/binutils/binutils-${pkgver}.tar.xz")
sha256sums=('645c25f563b8adc0a81dbd6a41cffbf4d37083a382e02d5d3df4f65c09516d00')

build() {
    mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

    ../binutils-${pkgver}/configure \
        --build=${MINGW_CHOST} \
        --prefix=${MINGW_PREFIX} \
        --target=${_target} \
        --libdir=${MINGW_PREFIX}/lib/${_target} \
        --enable-multilib \
        --enable-interwork \
        --with-gnu-as \
        --with-gnu-ld \
        --disable-nls \
        --enable-ld=default \
        --enable-gold \
        --enable-plugins \
        --enable-deterministic-archives

    make
}

package() {
    cd "${srcdir}"/build-${MSYSTEM}

    make DESTDIR="${pkgdir}" install

    cd ${pkgdir}${MINGW_PREFIX}

    for info in as bfd binutils ctf-spec gprof ld; do
      mv share/info/${info}.info share/info/${_target}-${info}.info
    done
}
